#include "gdevice.h"

struct gdevice *find_device_by_key(struct gdevice *pgdevhead,int key)
{
    struct gdevice *p = pgdevhead; 

    if(NULL == pgdevhead)
    {
        return NULL; 
    } 

    p = pgdevhead;

    while(NULL != p)
    {
        if(p->key == key)
        {
            return p;   
        }
        p = p->next;
    } 
    return NULL;
}

int set_gpio_gdevice_status(struct gdevice *pgdev)
{
    if(NULL == pgdev)
    {
        return -1;  
    }
    if(-1 != pgdev->gpio_pin)
    {
        if(-1 != pgdev->gpio_mode)
        {
            pinMode(pgdev->gpio_pin,pgdev->gpio_mode); //配置引脚的输入输出模式
        }
        if(-1 != pgdev->gpio_status)
        {
            digitalWrite(pgdev->gpio_pin,pgdev->gpio_status); //当配置为输出模式时，引脚高低状态
        }
    }

    return 0;
}